

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.CarLine;
import com.loong.loong.hik.service.CarLineService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车道
 *
 * @author jinyiang
 * @date 2023-03-30 13:47:53
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/carline" )
@Api(value = "carline", tags = "车道管理")
public class CarLineController {

    private final  CarLineService carLineService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param carLine 车道
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_carline_view')" )
    public R getCarLinePage(Page page, CarLine carLine) {
        return R.ok(carLineService.page(page, Wrappers.query(carLine)));
    }


    /**
     * 通过id查询车道
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_carline_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(carLineService.getById(id));
    }

    /**
     * 新增车道
     * @param carLine 车道
     * @return R
     */
    @ApiOperation(value = "新增车道", notes = "新增车道")
    @SysLog("新增车道" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_carline_add')" )
    public R save(@RequestBody CarLine carLine) {
        return R.ok(carLineService.save(carLine));
    }

    /**
     * 修改车道
     * @param carLine 车道
     * @return R
     */
    @ApiOperation(value = "修改车道", notes = "修改车道")
    @SysLog("修改车道" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_carline_edit')" )
    public R updateById(@RequestBody CarLine carLine) {
        return R.ok(carLineService.updateById(carLine));
    }

    /**
     * 通过id删除车道
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除车道", notes = "通过id删除车道")
    @SysLog("通过id删除车道" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_carline_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(carLineService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param carLine 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_carline_export')" )
    public List<CarLine> export(CarLine carLine) {
        return carLineService.list(Wrappers.query(carLine));
    }
}
